package sjtu.ist.warehouse4ws.dao.cust;

import java.util.List;

import org.springframework.orm.hibernate3.HibernateTemplate;

import sjtu.ist.warehouse4ws.dao.BaseDaoHibernate;
import sjtu.ist.warehouse4ws.dynamicDS.CustInterceptor;
import sjtu.ist.warehouse4ws.model.CustEpcunits;
import sjtu.ist.warehouse4ws.model.Epcunits;




public class CustEpcunitsDaoHibernate extends BaseDaoHibernate<CustEpcunits> implements CustEpcunitsDao{

	@Override
	public List findAllCustEpcunits() {
		// TODO Auto-generated method stub
		//return (List<CustEpcunits>)getSessionFactory().openSession(new CustInterceptor("6")).createQuery("from CustEpcunits").list();
		return  (List<CustEpcunits>)getSession().createSQLQuery("select * from cust_epcunits").addEntity(CustEpcunits.class).list();
	}

	@Override
	public String save(CustEpcunits epcUnits) {
		// TODO Auto-generated method stub
		getHibernateTemplate().setFlushMode(HibernateTemplate.FLUSH_EAGER); 
		return (String)getHibernateTemplate().save(epcUnits);
	}

	@Override
	public List findById(String id) {
		// TODO Auto-generated method stub
		return (List<CustEpcunits>)getSession().createSQLQuery("select cust_epcunits.* from cust_epcunits where cust_epcunits.id='"+id+"'").addEntity(CustEpcunits.class).list();
	}

	@Override
	public CustEpcunits getCustEpc(String id) {
		// TODO Auto-generated method stub
		return (CustEpcunits)getHibernateTemplate().get(CustEpcunits.class, id);
	}

	@Override
	public List<CustEpcunits> findByGroupId(Integer groupId) {
		// TODO Auto-generated method stub
		String hql="select cust_epcunits.* from cust_epcunits where cust_epcunits.groupId=?";		
		return this.findByHql(hql, new Object[]{groupId});
	}

	@Override
	public List<CustEpcunits> findByGroupAndVersion(String groupId,
			String versionId) {
		// TODO Auto-generated method stub
		String hql="select cust_epcunits.* from cust_epcunits where cust_epcunits.groupId=? and cust_epcunits.versionId=?";		
		return this.findByHql(hql, new Object[]{groupId,versionId});
	}
}
